﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowerbird.Api.Dtos;
using System.Net;

namespace Bowerbird.Api.Controllers
{
    public class UserController : BaseController
    {
        [HttpPost]
        public ActionResult LogIn(string identityProvider, string nameIdentifier, string name)
        {
            try
            {
                UserService service = new UserService();

                User user = service.LogIn(identityProvider, nameIdentifier, name);

                return Json(user);
            }
            catch
            {
                // ToDo: catch more specific errors

                return new HttpStatusCodeResult((int)HttpStatusCode.InternalServerError);
            }
        }

        [HttpPost]
        public ActionResult Edit(User user)
        {
            try
            {
                UserService service = new UserService();

                user = service.Edit(user);

                return Json(user);
            }
            catch (ArgumentException ex)
            {
                return new HttpStatusCodeResult((int)HttpStatusCode.NotFound, ex.Message);
            }
            catch (Exception)
            {
                return new HttpStatusCodeResult((int)HttpStatusCode.InternalServerError);
            }

        }

    }
}
